// Baseline.h: interface for the CBaseline class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_BASELINE_H__5AC93CBD_8AA0_484A_BC80_77BB31743ADA__INCLUDED_)
#define AFX_BASELINE_H__5AC93CBD_8AA0_484A_BC80_77BB31743ADA__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#pragma warning(disable:4273)

#include "GNSSRinex.h"
#include "MatrixDLL.h"

namespace NGSS{
class AFX_CLASS_EXPORT CaBaseline
{
public:
	void ClearContents();
	CaBaseline();
	
	~CaBaseline();

	BOOL	Attach(BASELINE*pData);
	BASELINE* Detach();

	CaRinexData*GetRNXStart();
	CaRinexData*GetRNXEnd();
	YMDHMS*	GetFirstTime();
	YMDHMS* GetLastTime();
	float	GetObsTime();
	void	SetRNXStart(CaRinexData*pRnxFile);;
	void	SetRNXEnd(CaRinexData*pRnxFile);;

	BOOL CalcBaseLine(vector<OBSPRN>*pObsPrnLst,int &indexFro,int &indexGto,BOOL bDoubleDifference = false,CallBackProgress callBackProgr=NULL);
	BOOL IsInit();
	BOOL InitBaseLine(BASELINE *pbaseline = NULL,DDOBSRECLIST*plist = NULL);
	BOOL LoadBaseLine(CString szBaseLineFileName);
	BOOL SaveBaseLine(CString szBaseLineFileName);
	BOOL CalcDoulDifference(char* szobstype="L1_FULL",CallBackProgress callBackProgr=NULL);
	BASELINE * GetDDdata();
	double* GetResult();
	long GetDDobsRecCount(void);

public:
	BOOL	  IsDDdataValid(BASELINE * pData);
	int		  GetRecMatchCount(PDDOBSREC prec,PDDOBSREC precNxt,vector<OBSPRN>*pInCludeObsPrn=NULL);
	vector<OBSPRN>*GetRecMatchPRNlist(PDDOBSREC prec,PDDOBSREC precNxt,vector<OBSPRN>*pInCludeObsPrn=NULL);

	
	int	   GetDDobsCount(const PDDOBSREC prec,vector<OBSPRN>*pInCludeObsPrn=NULL);
	BOOL   IsPrnInOBSPRNlist(unsigned char basePRN,unsigned char obsPRN,vector<OBSPRN>*pInCludeObsPrn);
	
	// _obs_data
	double  GetRecordObsData(vector<DDOBS>*pData,unsigned char prn);
	double  GetMaxRecordObsData();
	double	GetMinRecordObsData();
	PDDOBS	GetDDobsFromPRN(PDDOBSREC pddRec,unsigned char PRN);
	// _manipulation 
	void DeleteContents();

	// _results
	int		GetBaseIndexFromPRN(unsigned char basePRN);
	unsigned char	GetBasePRNFromIndex( int Index);
	vector<double>* GetObsData( unsigned char basePRN,unsigned char obsPRN,int& indexFrom,int& indexGoto);
	vector<BREAKPOINT>*GetObsDataBreak(unsigned char basePRN,unsigned char obsPRN,int& indexFrom,int& indexGoto);
	vector<BASEPRN>*GetBasPrnList();
	vector<OBSPRN>*GetObsPrnList(int& indexFrom,int& indexGoto);
	vector<unsigned char>*	GetObsPrnList(unsigned char basePRN);
	vector<SDV>* Getdv(int basePRNIndex,unsigned char obsPRN,int& indexFrom,int& indexGoto,BOOL boulCalc=FALSE);
	vector<SDV>* GetCycleSlip(int basePRNIndex,unsigned char obsPRN,int& indexFrom,int& indexGoto);
	BOOL		 RectifyCycleSlip(vector<SDV>*pCycleSlp);
	vector<BASELINEDATA>*CalcDoulBaseLineByEpoch(vector<OBSPRN>*pObsPrnLst,CRDCARTESIAN*pCrdFrom,CRDCARTESIAN* pCrdGoto,int indexFro,int indexGto);

	double Distance( CRDCARTESIAN* pcrdSite, CRDCARTESIAN* pcrdSat );
protected:
	void TraceMatrix(double*pArray,int rows,int cols,char*szname="");
	BOOL GetP(CaMatrix&P,vector<OBSPRN>*pObsPrnLst,int indexFro,int indexGto,BOOL bDoubleDifference = false);
	BOOL CalcTripDifferCoefficient(vector<OBSPRN>*pObsPrnLst,CRDCARTESIAN*pCrdFrom,CRDCARTESIAN* pCrdGoto,int indexFro,int indexGto,CaMatrix&mB,CaMatrix&mL,CallBackProgress callBackProgr=NULL);
	BOOL CalcDoulDifferCoefficient(vector<OBSPRN>*pObsPrnLst,CRDCARTESIAN*pCrdFrom,CRDCARTESIAN* pCrdGoto,int indexFro,int indexGto,CaMatrix&mB,CaMatrix&mA,CaMatrix&mL,CallBackProgress callBackProgr=NULL);
	BOOL AdjustBaseLine(const CaMatrix&B,const CaMatrix&L,const CaMatrix&P,CaMatrix&X,CaMatrix&dv,double &sigma,CallBackProgress callBackProgr = NULL);
	BOOL InitBaseLineFromData(BASELINE * pData);

private:
	DDOBSRECLIST*m_pDDrecList;
	BASELINE m_tempBaseLine;

	CaRinexData* m_pRNXFrom;
	CaRinexData* m_pRNXGoto;
	BASELINE * m_pData;

public:
	vector<BASEPRN>* m_pbasePRNlist;
//	vector<OBSPRN> *m_prn_lst;
//	vector<SDV> m_dv;
	CString szComment;
};
}

#endif // !defined(AFX_BASELINE_H__5AC93CBD_8AA0_484A_BC80_77BB31743ADA__INCLUDED_)
